import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {logger} from './middleware/logger/logger.middleware'
import { TransformInterceptor } from './interceptor/transform/transform.interceptor';
import { HttpExceptionFilter } from './filter/http-exception/http-exception.filter';
import { AllExceptionsFilter } from './filter/any-exception/any-exception.filter';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setGlobalPrefix('api');
  app.use(logger)//监听所有请求路由，并打印日志
  app.useGlobalInterceptors(new TransformInterceptor()); //使用全局拦截器
  //过滤处理HTTP异常
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalFilters(new AllExceptionsFilter());
   // 配置 Swagger
   const options = new DocumentBuilder()
   .setTitle('film-server')
   .setDescription('NestJs接口')
   .setVersion('1.0')
   // .addTag('test') // 添加分组标签
   .build();
 const document = SwaggerModule.createDocument(app, options);
 SwaggerModule.setup('api-doc', app, document); 
  await app.listen(3000);
}
bootstrap();
